﻿$(document).ready(function () {

    if ($("#result").html() == "添加成功" || $("#result").html() == "修改成功") {
        //关闭当前对话框并刷新父页面
        $(window.top.document).find("#refreshBtn").click();
        window.top.art.dialog.get('operationmanageusercreate').close();
    }

    $("#selectParentUnit").click(function () {
        artDialogForm("/User/PickParentUnit", "选择所属单位", "operationmanageusercreatepickparentunit", 400, 300);
    });

    var validator = $("#usercreateform").validate({
        errorPlacement: function (error, element) {
            error.appendTo(element.parent());
        },
        rules: {
            UserId:
            {
                required: true,
                maxlength: 50
            },
            SexType:
            {
                required: true
            },
            repeatpassword:
            {
                equalTo: "#password"
            },
            telPhone:
            {
                maxlength: 50
            },
            RocPhone:
            {
                maxlength: 50
            },
            RealName:
            {
                maxlength: 50
            },
            CustomerID:
            {
                required: true,
                maxlength: 50
            },
            address:
            {
                maxlength: 50
            },
            Fmemo:
            {
                maxlength: 255
            }
        }
        //onfocusout: function(element) { $(element).valid(); }
    });

    $("#submitBtn").click(function () {
        if (validator.form()) {
            //sha1加密密码,如果是空串，说明没有修改密码，不再对空串进行加密
            if ($("#password").val().length > 0) {
                $("#LoginPassword").val(encrypt($("#password").val()));
            }
            $("#usercreateform").submit();
        }
    });
});

function encrypt(str) {
    //return str;
    return $.encoding.digests.hexSha1Str(str);
}